module Admin::AdvertsHelper
  
  
  def render_advert(advert)
    
    #iframe
    if advert.is_iframe
      build_iframe_html(advert)
    elsif advert.is_script
      build_script_html(advert)
    elsif advert.is_custom_banner
      build_custom_banner_html(advert)
    elsif advert.is_image_banner
      build_image_banner_html(advert)
    end
    
    
    
  end
  
  private 
  def build_image_banner_html(advert)
    html = link_to image_tag(advert.image_banner_src, :border=>"0", :width=>advert.width, :height=>advert.height), advert.image_banner_href
  end
  
  def build_custom_banner_html(advert)   
    html = link_to image_tag(advert.custom_banner_image.url, :border=>"0", :width=>advert.width, :height=>advert.height), advert.custom_banner_href
  end
  def build_script_html(advert)
    html=""
    html +="<iframe src=\""
    html +=script_advert_url(advert, :canvas=>false)
    html +="\""
    html +="scrolling=\"no\" border=\"0\" marginwidth=\"0\" style=\"border:none;\" frameborder=\"0\"" 
    html +=" width=\"#{advert.width}\""
    html +=" height=\"#{advert.height}\""
    
    html +="</iframe>"  
  end
  
  def build_iframe_html(advert)
    html=""
    html +="<iframe src=\""
    html +=advert.iframe_src
    html +="\""
    html +="scrolling=\"no\" border=\"0\" marginwidth=\"0\" style=\"border:none;\" frameborder=\"0\"" 
    html +=" width=\"#{advert.width}\""
    html +=" height=\"#{advert.height}\""
    
    html +="</iframe>"
  end
end
